package com.jt.www.admin.stats.controller;

import com.jt.www.admin.stats.service.InsuranceDataService;
import com.jt.www.model.Insurancedata.DataApiBean;
import com.jt.www.model.reps.GenericDataResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;

@RestController
@RequestMapping("/api/")
@Api(value = "教保网统计查询列表接口", tags = {"STATS-DATA-API"}, description = "教保网统计查询列表接口")
public class InsuranceDataController {
    public static final Logger log = LoggerFactory.getLogger(InsuranceDataController.class);
    @Autowired
    InsuranceDataService insuranceDataService;

    /**
     * 统保业务统计表
     *
     * @param dataApiBean
     * @return
     */
    @ApiOperation(value = "统保业务统计表", notes = "统保业务统计表")
    @PostMapping("v1/business_details")
    public ResponseEntity<?> getBusinessDataList(@RequestBody DataApiBean dataApiBean) {
        try {
            return GenericDataResponse.okWithData(insuranceDataService.getUnfiedInsureProject(dataApiBean));
        } catch (Exception e) {
            e.printStackTrace();
            return GenericDataResponse.ng(e.getMessage());
        }
    }

    /**
     * 统保附加险投保率统计
     *
     * @param dataApiBean
     * @return
     */
    @PostMapping("v1/add_details")
    @ApiOperation(value = "统保附加险投保率统计", notes = "统保附加险投保率统计")
    public ResponseEntity<?> getAddList(@RequestBody DataApiBean dataApiBean) {
        try {
            return GenericDataResponse.okWithData(insuranceDataService.getAdditionInsureRate(dataApiBean));
        } catch (Exception e) {
            e.printStackTrace();
            return GenericDataResponse.ng(e.getMessage());
        }
    }

    /**
     * 业务同比情况表
     *
     * @param dataApiBean
     * @return
     */
    @ApiOperation(value = "业务同比情况表", notes = "业务同比情况表")
    @PostMapping("v1/period_details")
    public ResponseEntity<?> getBusinessGrewList(@RequestBody DataApiBean dataApiBean) {
        try {
            return GenericDataResponse.okWithData(insuranceDataService.getBusinessDataList(dataApiBean));
        } catch (Exception e) {
            e.printStackTrace();
            return GenericDataResponse.ng(e.getMessage());
        }
    }

    /**
     * 云南专用投保统计表
     *
     * @param dataApiBean
     * @return
     */
    @ApiOperation(value = "云南专用投保统计表", notes = "云南专用投保统计表")
    @PostMapping("v1/ynins_details")
    public ResponseEntity<?> getYnList(@RequestBody DataApiBean dataApiBean) {
        try {
            return GenericDataResponse.okWithData(insuranceDataService.getYunnanSpecial(dataApiBean));
        } catch (Exception e) {
            e.printStackTrace();
            return GenericDataResponse.ng(e.getMessage());
        }
    }

    /**
     * 同期投保情况明细表
     *
     * @param dataApiBean
     * @return
     */
    @ApiOperation(value = "同期投保情况明细表", notes = "同期投保情况明细表")
    @PostMapping("v1/periodins_details")
    public ResponseEntity<?> getPeriodinsList(@RequestBody DataApiBean dataApiBean) {
        try {
            return GenericDataResponse.okWithData(insuranceDataService.getPeriodinsList(dataApiBean));
        } catch (Exception e) {
            e.printStackTrace();
            return GenericDataResponse.ng(e.getMessage());
        }
    }

    /**
     * 实责转化安责情况表
     *
     * @param dataApiBean
     * @return
     */
    @ApiOperation(value = "实责转化安责情况表", notes = "实责转化安责情况表")
    @PostMapping("v1/convert_details")
    public ResponseEntity<?> getConvertList(@RequestBody DataApiBean dataApiBean) {
        try {
            return GenericDataResponse.okWithData(insuranceDataService.getConvertList(dataApiBean));
        } catch (Exception e) {
            e.printStackTrace();
            return GenericDataResponse.ng(e.getMessage());
        }
    }

    /**
     * 安责险统计表
     *
     * @param dataApiBean
     * @return
     */
    @ApiOperation(value = "安责险统计表", notes = "安责险统计表")
    @PostMapping("v1/safeins_details")
    public ResponseEntity<?> getSafeinsList(@RequestBody DataApiBean dataApiBean) {
        try {
            return GenericDataResponse.okWithData(insuranceDataService.getSafeinsList(dataApiBean));
        } catch (Exception e) {
            e.printStackTrace();
            return GenericDataResponse.ng(e.getMessage());
        }
    }

    /**
     * 汇总表
     *
     * @param dataApiBean
     * @return
     */
    @ApiOperation(value = "汇总表", notes = "汇总表")
    @PostMapping("v1/total")
    public ResponseEntity<?> getTotalStatus(@RequestBody DataApiBean dataApiBean) {
        try {
            return GenericDataResponse.okWithData(insuranceDataService.getTotalStatus(dataApiBean));
        } catch (Exception e) {
            e.printStackTrace();
            return GenericDataResponse.ng(e.getMessage());
        }
    }

    /**
     * 统保示范项目
     *
     * @param dataApiBean
     * @return
     */
    @ApiOperation(value = "统保示范项目", notes = "统保示范项目")
    @PostMapping("v1/unit")
    public ResponseEntity<?> getUnitTotal(@RequestBody DataApiBean dataApiBean) {
        try {
            return GenericDataResponse.okWithData(insuranceDataService.getUnitTotal(dataApiBean));
        } catch (Exception e) {
            e.printStackTrace();
            return GenericDataResponse.ng(e.getMessage());
        }
    }

    /**
     * 区域统保
     *
     * @param dataApiBean
     * @return
     */
    @ApiOperation(value = "区域统保", notes = "区域统保")
    @PostMapping("v1/part")
    public ResponseEntity<?> getPartTotal(@RequestBody DataApiBean dataApiBean) {
        try {
            return GenericDataResponse.okWithData(insuranceDataService.getPartTotal(dataApiBean));
        } catch (Exception e) {
            e.printStackTrace();
            return GenericDataResponse.ng(e.getMessage());
        }
    }

    /**
     * 延伸业务
     *
     * @param dataApiBean
     * @return
     */
    @ApiOperation(value = "延伸业务", notes = "延伸业务")
    @PostMapping("v1/extend")
    public ResponseEntity<?> getExtend(@RequestBody DataApiBean dataApiBean) {
        try {
            return GenericDataResponse.okWithData(insuranceDataService.getExtend(dataApiBean));
        } catch (Exception e) {
            e.printStackTrace();
            return GenericDataResponse.ng(e.getMessage());
        }
    }

    /**
     * 我学保
     *
     * @param dataApiBean
     * @return
     */
    @ApiOperation(value = "我学保", notes = "我学保")
    @PostMapping("v1/wxb")
    public ResponseEntity<?> getWoXueBao(@RequestBody DataApiBean dataApiBean) {
        try {
            return GenericDataResponse.okWithData(insuranceDataService.getWoXueBao(dataApiBean));
        } catch (Exception e) {
            e.printStackTrace();
            return GenericDataResponse.ng(e.getMessage());
        }
    }

    /**
     * 学平险
     *
     * @param dataApiBean
     * @return
     */
    @ApiOperation(value = "学平险", notes = "学平险")
    @PostMapping("v1/xp")
    public ResponseEntity<?> getXuePing(@RequestBody DataApiBean dataApiBean) {
        try {
            return GenericDataResponse.okWithData(insuranceDataService.getXuePing(dataApiBean));
        } catch (Exception e) {
            e.printStackTrace();
            return GenericDataResponse.ng(e.getMessage());
        }
    }

    /**
     * 校车业务
     *
     * @param dataApiBean
     * @return
     */
    @ApiOperation(value = "校车业务", notes = "校车业务")
    @PostMapping("v1/school_bus")
    public ResponseEntity<?> getSchoolBus(@RequestBody DataApiBean dataApiBean) {
        try {
            return GenericDataResponse.okWithData(insuranceDataService.getSchoolBus(dataApiBean));
        } catch (Exception e) {
            e.printStackTrace();
            return GenericDataResponse.ng(e.getMessage());
        }
    }

    /**
     * 安全咨询服务
     *
     * @param dataApiBean
     * @return
     */
    @ApiOperation(value = "安全咨询服务", notes = "安全咨询服务")
    @PostMapping("v1/consult")
    public ResponseEntity<?> getConsult(@RequestBody DataApiBean dataApiBean) {
        try {
            return GenericDataResponse.okWithData(insuranceDataService.getConsult(dataApiBean));
        } catch (Exception e) {
            e.printStackTrace();
            return GenericDataResponse.ng(e.getMessage());
        }
    }

    /***-----------------------------------------------导出excel--------------------------------------------------------- */
    /**
     * 安全咨询服务
     *
     * @param dataApiBean
     * @return
     */
    @ApiOperation(value = "Excel导出", notes = "Excel导出", produces = "application/octet-stream")
    @PostMapping(value = "v1/excel/{type}")
    public void getDataByExcel(@RequestBody DataApiBean dataApiBean, @PathVariable("type") String type, HttpServletResponse response) {
        try {
            insuranceDataService.getDataByExcel(dataApiBean, type, response);
        } catch (Exception e) {
            log.error(e.getMessage());
        }
    }
}
